package 设计模式.fatoryabs.pizza.pizza.order;




import 设计模式.fatoryabs.pizza.pizza.Pizza;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public  class OrderPizza {
    AbsFactory absFactory;
    public OrderPizza(AbsFactory absFactory){
        setAbsFactory(absFactory);
    }
    private void setAbsFactory(AbsFactory absFactory){
        Pizza pizza=null;
        String orderType;
        this.absFactory=absFactory;
        do{
            orderType=getType();
            pizza=absFactory.createPizza(orderType);
            if (pizza!=null){
                pizza.prepare();
                pizza.bake();
                pizza.cut();
                pizza.box();
            }else {
                System.out.println("购买失败");
                break;
            }
        }while (true);
    }
    //父方法

    private String getType(){
        try {
            BufferedReader strin=new BufferedReader(new InputStreamReader(System.in));
            System.out.println("input 披萨种类");
            String str=strin.readLine();
            return str;
        }catch (IOException e){
            e.printStackTrace();
            return "";
        }
    }
}

